var TimerComponent = (function () {
    /**
     * 等待指定时间
     * @param millisecond 毫秒
     */
    function WaitAsync(millisecond) {
        return new Promise(reslove => setTimeout(reslove, millisecond));
    }

    /**
     * 等待到达指定时间
     * @param year 年
     * @param month 月
     * @param date 日(默认1)
     * @param hours 时(默认0)
     * @param minutes 分(默认0)
     * @param seconds 秒(默认0)
     * @param millisecond 毫秒(默认0)
     */
    function WaitTillAsync(year, month, date = 1, hours = 0, minutes = 0, seconds = 0, millisecond = 0) {
        return new Promise(reslove => setTimeout(reslove, new Date(year, month - 1, date, hours, minutes, seconds, millisecond).getTime() - new Date().getTime()));
    }

    /**
     * 等待条件满足
     * @param condition 条件
     * @param interval 刷新间隔(默认100毫秒)
     * @param timeout 超时时间(默认永不超时)
     */
    async function WaitUntilAsync(condition, interval = 100, timeout = -1) {
        if (condition()) {
            return true;
        } else {
            if (timeout == -1) {
                do {
                    await this.WaitAsync(interval);
                } while (!condition());
                return true;
            } else {
                const time = Date.now() + timeout;
                let now = Date.now();
                do {
                    await this.WaitAsync(interval);
                    now = Date.now();
                } while (now < time && !condition());
                return now < time;
            }
        }
    }

    return {
        WaitAsync,
        WaitTillAsync,
        WaitUntilAsync,
    };
})();